//
// Created by Administrator on 2023/11/18.
//
#include "iostream"
#include "cstring"

using namespace std;

const int N = 510, INF = 0x3f3f3f3f;
int dp[N][N];
int g[N][N];


void m1(){
    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            cin >> g[i][j];
        }
    }
    //memset(dp,-0x3f,sizeof dp);

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i + 1; j++) {          //因为有负数，所以应该将两边也设为-INF
            dp[i][j] = -INF;
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + g[i][j];
        }
    }

    int res = -INF;
    for (int i = 1; i <= n; ++i) {
        res = max(dp[n][i], res);
    }
    cout << res;
}
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            cin>>dp[i][j];
        }
    }

    for(int i=n;i>=1;i--){
        for(int j=1;j<=n;j++){
            dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+dp[i][j];
        }
    }
    cout<<dp[1][1]<<endl;
}